<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 300px;
      height: 300px;
      border: 1px solid black;
    }
  </style>
</head>
<body>
  <div class="box">T E S T</div>
  <button>生成随机颜色</button>
</body>
</html>

<script>
// 需求：
  // 1、点击 button   
  // 2、随机生成一个 rgb(xx, xx, xx) 的字符串   
  // 3、将该字符串赋值给 dom.style.backgroundColor

// 随机生成一个 0~255 的数字
function randomNum() {
  return  Math.floor(Math.random() * 256);
}

var box = document.querySelector('.box');
var btn = document.querySelector('button');

btn.onclick = function() {
  box.style.backgroundColor = `rgb(${randomNum()}, ${randomNum()}, ${randomNum()})`;
}

</script>